package com.rabbiter.oes.controller;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rabbiter.oes.dto.StudentExamDTO;
import com.rabbiter.oes.entity.ExamManage;
import com.rabbiter.oes.entity.Student;
import com.rabbiter.oes.enums.RoleEnum;
import com.rabbiter.oes.result.R;
import com.rabbiter.oes.service.impl.ExamManageServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "学生获取试卷接口")
@RestController
@RequestMapping("/student")
public class StudentExamManageController extends BaseController{

    @Autowired
    private ExamManageServiceImpl examManageService;

    @ApiOperation(value = "学生分页查询试卷", notes = "学生分页查询试卷", httpMethod = "GET")
    @PostMapping("/exams")
    public R studentExams(HttpServletRequest request, @RequestBody StudentExamDTO dto) {
        // 获取访问该接口用户身份
        RoleEnum role = getRole(request);
        Assert.isTrue(role == RoleEnum.STUDENT, "请使用学生账号访问该接口");
        // 获取访问接口学生信息
        Student student = getLoginStudent(request);
        IPage<ExamManage> all = examManageService.studentFindPage(dto, student);
        return R.ok().data(all);
    }

}
